<?php

class ConfAction extends CommonAction{
public function index()
{
$conf_res = M('Conf')->where('is_effect = 1 and is_conf = 1')->order('group_id asc,sort asc')->findAll();
foreach($conf_res as $k=>$v)
{
$v['value'] = htmlspecialchars($v['value']);
if($v['name']=='TEMPLATE')
{
$directory = APP_ROOT_PATH.'app/Tpl/';
$dir = @opendir($directory);
$tmpls     = array();
while (false !== ($file = @readdir($dir)))
{
if($file!='.'&&$file!='..')
$tmpls[] = $file;
}
@closedir($dir);
$v['input_type'] = 1;
$v['value_scope'] = $tmpls;
}
elseif($v['name']=='SHOP_LANG')
{
$directory = APP_ROOT_PATH.'app/Lang/';
$dir = @opendir($directory);
$tmpls     = array();
while (false !== ($file = @readdir($dir)))
{
if($file!='.'&&$file!='..')
$tmpls[] = $file;
}
@closedir($dir);
$v['input_type'] = 1;
$v['value_scope'] = $tmpls;
}
else
$v['value_scope'] = explode(',',$v['value_scope']);
$conf[$v['group_id']][] = $v;
}
$this->assign('conf',$conf);
$this->display();
}
public function update()
{
$conf_res = M('Conf')->where('is_effect = 1 and is_conf = 1')->findAll();
foreach($conf_res as $k=>$v)
{
conf($v['name'],$_REQUEST[$v['name']]);
if($v['name']=='URL_MODEL'&&$v['value']!=$_REQUEST[$v['name']])
{
clear_auto_cache('byouhui_filter_nav_cache');
clear_auto_cache('cache_shop_acate_tree');
clear_auto_cache('cache_shop_cate_tree');
clear_auto_cache('cache_youhui_cate_tree');
clear_auto_cache('city_list_result');
clear_auto_cache('fyouhui_filter_nav_cache');
clear_auto_cache('get_help_cache');
clear_auto_cache('page_image');
clear_auto_cache('tuan_filter_nav_cache');
clear_auto_cache('youhui_page_recommend_youhui_list');
clear_auto_cache('ytuan_filter_nav_cache');
clear_auto_cache('store_filter_nav_cache');
clear_dir_file(get_real_path().'public/runtime/app/data_caches/');
clear_dir_file(get_real_path().'public/runtime/app/tpl_caches/');
clear_dir_file(get_real_path().'public/runtime/app/tpl_compiled/');
clear_dir_file(get_real_path().'public/runtime/app/data_caches/');
clear_dir_file(get_real_path().'public/runtime/data/page_static_cache/');
clear_dir_file(get_real_path().'public/runtime/data/dynamic_avatar_cache/');
}
}
$sys_configs = M('Conf')->findAll();
$config_str = "<?php\n";
$config_str .= "return array(\n";
foreach($sys_configs as $k=>$v)
{
$config_str.="'".$v['name']."'=>'".addslashes($v['value'])."',\n";
}
$config_str.=");\n ?>";
$filename = get_real_path().'public/sys_config.php';
if (!$handle = fopen($filename,'w')) {
$this->error(l('OPEN_FILE_ERROR').$filename);
}
if (fwrite($handle,$config_str) === FALSE) {
$this->error(l('WRITE_FILE_ERROR').$filename);
}
fclose($handle);
save_log(l('CONF_UPDATED'),1);
write_timezone();
$this->success(L('UPDATE_SUCCESS'));
}
public function mobile()
{
$config = M('MConfig')->findAll();
$this->assign('config',$config);
$this->display();
}
public function savemobile()
{
foreach($_POST as $k=>$v)
{
M('MConfig')->where("code='".$k."'")->setField('val',$v);
}
$this->success('保存成功');
}
public function insertnews()
{
$name='MConfigList';
$model = D ($name);
if (false ===$data= $model->create ()) {
$this->error ( $model->getError () );
}
$data['is_verify'] = 1;
$data['group'] = 4;
$list=$model->add ($data);
if ($list!==false) {
$this->success (L('INSERT_SUCCESS'));
}else {
$this->error (L('INSERT_FAILED'));
}
}
function edit() {
$name = 'MConfigList';
$model = D($name);
$id = $_REQUEST [$model->getPk ()];
$vo = $model->getById($id);
$this->assign ( 'vo',$vo );
$this->display ();
}
public function news()
{
$map = $this->_search ();
if (method_exists ( $this,'_filter')) {
$this->_filter ( $map );
}
$map['group'] = 4;
$name=$this->getActionName();
$model = D ('MConfigList');
if (!empty ( $model )) {
$this->_list ( $model,$map );
}
$this->display ();
return;
}
function updatenews() {
$name='MConfigList';
$model = D ( $name );
if (false === $data = $model->create ()) {
$this->error ( $model->getError () );
}
$list=$model->save ($data);
$id = $data[$model->getPk()];
if (false !== $list) {
$this->success (L('UPDATE_SUCCESS'));
}else {
$this->error (L('UPDATE_FAILED'));
}
}
public function foreverdelete() {
$result = array('isErr'=>0,'content'=>'');
$id = $_REQUEST['id'];
if(!empty($id))
{
$name='MConfigList';
$model = D($name);
$pk = $model->getPk ();
$condition = array ($pk =>array ('in',explode ( ',',$id ) ) );
if(false !== $model->where ( $condition )->delete ())
{
}
else
{
$result['isErr'] = 1;
$result['content'] = L('FOREVER_DELETE_SUCCESS');
}
}
else
{
$result['isErr'] = 1;
$result['content'] = L('FOREVER_DELETE_FAILED');
}
die(json_encode($result));
}
public function toogle_status()
{
$id = intval($_REQUEST['id']);
$ajax = intval($_REQUEST['ajax']);
$field = $_REQUEST['field'];
$info = $id.'_'.$field;
$c_is_effect = M('MConfigList')->where('id='.$id)->getField($field);
$n_is_effect = $c_is_effect == 0 ?1 : 0;
M('MConfigList')->where('id='.$id)->setField($field,$n_is_effect);
save_log($info.l('SET_EFFECT_'.$n_is_effect),1);
$this->ajaxReturn($n_is_effect,l('SET_EFFECT_'.$n_is_effect),1)	;
}
}

?>